package com.cjg.xiancheng;

public class proxyTest {
    public static void main(String[] args) {
        marryCompany marryCompany = new marryCompany(new Me());
        marryCompany.happyMarry();
    }
}
//代理和自己都要实现方法 提取出来
interface Marry{

    void happyMarry();
}
//真实对象
class Me implements  Marry{
    @Override
    public void happyMarry() {
        System.out.println("我在做梦了");
    }
}
//代理对象
class  marryCompany implements Marry{
    private  Marry Me;

    public marryCompany(Marry me) {
        this.Me = me;
    }

    @Override
    public void happyMarry() {
        before();
        Me.happyMarry();
        after();
    }

    private void after() {
        System.out.println("上床");
    }

    private void before() {
        System.out.println("梦醒了");
    }
}


